<?php
session_start ();
error_reporting(0);
include '_admin/include/sql.php';

// Auto generates point 10, 20, 30, 40, 50 or x2
$values = array (
		0 
);
array_push ( $values, 10, 10, 10, 10, 10, 10 );
array_push ( $values, 20, 20, 20, 20, 20 );
array_push ( $values, 30, 30, 30, 30 );
array_push ( $values, 40, 40, 40 );
array_push ( $values, 50, 50 );
array_push ( $values, 60 );
array_push ( $values, 100 ); // means: x2
array_push ( $values, 50000 ); // means: nhan dc 50K the nap

$size = count ( $values );
// Step 2: check if user have turns left or not.
// uu tien dung tai khoan khuyen mai truoc tai khoan chinh :D
// Sinh ra random mot so
if (!checkIfMemberHasMoreTurns ()){
	$tmp = array("id"=>"play","result"=>"-1","luotchoiconlai"=>0);	
	die (json_encode($tmp)); // Means: no more turns.
}

if (!checkIfMemberCanReceiveDailyGift ())
	$size = $size - 1; // Means: You're able to get only one lucky gift.
// Random
$rand = rand ( 0, $size - 1 );
$value = $values [$rand];
// Neu duoc qua may man thi set gia tri is_lucky de lan sau ko the nhan may man nua
// Dong thoi log gia tri qua vao history table
saveToDatabase($value);
// End
$luotchoiconlai = 0;
$luotchoiconlai = getLuotChoiConLai();
$tmp = array("id"=>"play","result"=>$value,"luotchoiconlai"=>$luotchoiconlai);
echo (json_encode($tmp));
// phia client se dua vao "result" de hien thong tin
?>